//
//  NSDate+Category_lib.h
//  bus
//
//  Created by hychen on 17/3/30.
//  Copyright © 2017年 Hychen. All rights reserved.
//

#import <Foundation/Foundation.h>

#define DateFormatYear @"yyyy"
#define DateFormatMonth @"yyyy-MM"
#define DateFormatDay @"yyyy-MM-dd"
#define DateFormatDayChinese @"yyyy年MM月dd日"
#define DateFormatDayHourMinuteChinese @"yyyy年MM月dd日 HH:mm"
#define DateFormatMonthDayHourMinuteChinese @"MM月dd日 HH:mm"
#define DateFormatMonthDay @"MM-dd"
#define DateFormatMinute @"yyyy-MM-dd HH:mm"
#define DateFormatSecond @"yyyy-MM-dd HH:mm:ss"
#define DateFormatDayDot @"yyyy.MM.dd"
#define DateFormatOnlyHourAndMinute @"HH:mm"

#define DateMinute_bb       60          // 一分60秒
#define DateHour_bb         3600        // 一小时3600秒
#define DateDay_bb          86400       // 一天86400秒
#define DateWeek_bb         604800      // 一周604800秒
#define DateYear_bb         31556926    // 一年31556926秒（不准确）

@interface NSDate (Category_lib)
#pragma mark - 格式化
/**
 *  根据格式把NSDate转换为字符串日期
 *  @param format 转换格式
 
 */
- (NSString *)format_lib:(NSString *)format;

/**
 *  根据格式把NSDate转换为年，如：2016
 
 */
- (NSString *)formatYear_lib;

/**
 *  根据格式把NSDate转换为年月，如：2016-06
 
 */
- (NSString *)formatYearMonth_lib;

/**
 *  根据格式把NSDate转换为年月日，如：2016-06-26
 
 */
- (NSString *)formatYearMonthDay_lib;

/**
 *  根据格式把NSDate转换为年月日，如：2016年6月26日
 
 */
- (NSString *)formatYearMonthDayChinese_lib;

/**
 *  根据格式把NSDate转换为年月日，如：2016年6月26日 12:23
 
 */
- (NSString *)formatYearMonthDayHourMinuteChinese_lib;

/**
 *  根据格式把NSDate转换为年月日，如：6月26日 12:23
 
 */
- (NSString *)formatMonthDayHourMinuteChinese_lib;

/**
 *  根据格式把NSDate转换为年月日时，如：2016-06-26 14:05
 
 */
- (NSString *)formatYearMonthDayHourMinute_lib;

/**
 *  根据格式把NSDate转换为年月日时，如：2016-06-26 14:05:00
 
 */
- (NSString *)formatYearMonthDayHourSecond_lib;

/**
 *  根据格式把NSDate转换为时分，如：14:05
 
 */
- (NSString *)formatMinuteSecond_lib;

/**
 *  根据格式把NSDate转换为月日，如：03-15
 
 */
- (NSString *)formatMonthDay_lib;

/**
 根据格式把NSDate转换为年月日，如：2016.06.26

 */
- (NSString *)formatYearMonthDayDot_lib;


+ (NSCalendar *) currentCalendar; // avoid bottlenecks

// Relative dates from the current date
+ (NSDate *) dateTomorrow;
+ (NSDate *) dateYesterday;
+ (NSDate *) dateWithDaysFromNow: (NSInteger) days;
+ (NSDate *) dateWithDaysBeforeNow: (NSInteger) days;
+ (NSDate *) dateWithHoursFromNow: (NSInteger) dHours;
+ (NSDate *) dateWithHoursBeforeNow: (NSInteger) dHours;
+ (NSDate *) dateWithMinutesFromNow: (NSInteger) dMinutes;
+ (NSDate *) dateWithMinutesBeforeNow: (NSInteger) dMinutes;

// Short string utilities
- (NSString *) stringWithDateStyle: (NSDateFormatterStyle) dateStyle timeStyle: (NSDateFormatterStyle) timeStyle;
- (NSString *) stringWithFormat: (NSString *) format;
@property (nonatomic, readonly) NSString *shortString;
@property (nonatomic, readonly) NSString *shortDateString;
@property (nonatomic, readonly) NSString *shortTimeString;
@property (nonatomic, readonly) NSString *mediumString;
@property (nonatomic, readonly) NSString *mediumDateString;
@property (nonatomic, readonly) NSString *mediumTimeString;
@property (nonatomic, readonly) NSString *longString;
@property (nonatomic, readonly) NSString *longDateString;
@property (nonatomic, readonly) NSString *longTimeString;

// Comparing dates
- (BOOL) isEqualToDateIgnoringTime: (NSDate *) aDate;

- (BOOL) isToday;
- (BOOL) isTomorrow;
- (BOOL) isYesterday;

- (BOOL) isSameWeekAsDate: (NSDate *) aDate;
- (BOOL) isThisWeek;
- (BOOL) isNextWeek;
- (BOOL) isLastWeek;

- (BOOL) isSameMonthAsDate: (NSDate *) aDate;
- (BOOL) isThisMonth;
- (BOOL) isNextMonth;
- (BOOL) isLastMonth;

- (BOOL) isSameYearAsDate: (NSDate *) aDate;
- (BOOL) isThisYear;
- (BOOL) isNextYear;
- (BOOL) isLastYear;

- (BOOL) isEarlierThanDate: (NSDate *) aDate;
- (BOOL) isLaterThanDate: (NSDate *) aDate;

- (BOOL) isInFuture;
- (BOOL) isInPast;

// Date roles
- (BOOL) isTypicallyWorkday;
- (BOOL) isTypicallyWeekend;

// Adjusting dates
- (NSDate *) dateByAddingYears: (NSInteger) dYears;
- (NSDate *) dateBySubtractingYears: (NSInteger) dYears;
- (NSDate *) dateByAddingMonths: (NSInteger) dMonths;
- (NSDate *) dateBySubtractingMonths: (NSInteger) dMonths;
- (NSDate *) dateByAddingDays: (NSInteger) dDays;
- (NSDate *) dateBySubtractingDays: (NSInteger) dDays;
- (NSDate *) dateByAddingHours: (NSInteger) dHours;
- (NSDate *) dateBySubtractingHours: (NSInteger) dHours;
- (NSDate *) dateByAddingMinutes: (NSInteger) dMinutes;
- (NSDate *) dateBySubtractingMinutes: (NSInteger) dMinutes;

// Date extremes
- (NSDate *) dateAtStartOfDay;
- (NSDate *) dateAtEndOfDay;

// Retrieving intervals
- (NSInteger) secondsAfterDate: (NSDate *) aDate;
- (NSInteger) secondsBeforeDate: (NSDate *) aDate;
- (NSInteger) minutesAfterDate: (NSDate *) aDate;
- (NSInteger) minutesBeforeDate: (NSDate *) aDate;
- (NSInteger) hoursAfterDate: (NSDate *) aDate;
- (NSInteger) hoursBeforeDate: (NSDate *) aDate;
- (NSInteger) daysAfterDate: (NSDate *) aDate;
- (NSInteger) daysBeforeDate: (NSDate *) aDate;

- (NSInteger)distanceInDaysToDate:(NSDate *)anotherDate;
- (NSInteger)distanceInHoursToDate:(NSDate *)anotherDate;
- (NSInteger)distanceInMinutesToDate:(NSDate *)anotherDate;
- (NSInteger)distanceInSecondsToDate:(NSDate *)anotherDate;

// Decomposing dates
@property (readonly) NSInteger nearestHour;
@property (readonly) NSInteger hour;
@property (readonly) NSInteger minute;
@property (readonly) NSInteger seconds;
@property (readonly) NSInteger day;
@property (readonly) NSInteger month;
@property (readonly) NSInteger week;
@property (readonly) NSInteger weekday;
@property (readonly) NSInteger nthWeekday; // e.g. 2nd Tuesday of the month == 2
@property (readonly) NSInteger year;

@end
